package com.hbjycl.controller;

import javax.servlet.http.HttpServletRequest;



import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.servlet.ModelAndView;

import com.hbjycl.entity.Admin;


public abstract class BaseController
{
    protected static final int    GLRES_SAVE   = 0;
    protected static final int    GLRES_UPDATE = 1;
    protected static final int    GLRES_DELETE = 2;
    protected static final String MESSAGE      = "message";
    protected static final String LIST         = "list";
    protected static final String TIP_ERROR    = "tip_error";
    protected static final String TIP_INFO     = "tip_info";
    
    protected void addUser(ModelAndView mav)
    {
        Authentication auth = SecurityContextHolder.getContext().getAuthentication();
        if (auth != null)
        {
            Object obj = auth.getPrincipal();
            if ((obj != null) && (obj instanceof Admin))
            {
                Admin admin = (Admin) obj;
                mav.addObject("loginUser", admin);
            }
        }
    }
    
    protected Admin getLoginUser()
    {
        Authentication auth = SecurityContextHolder.getContext().getAuthentication();
        if (auth != null)
        {
            Object obj = auth.getPrincipal();
            if ((obj != null) && (obj instanceof Admin))
            {
                Admin admin = (Admin) obj;
                return admin;
            }
        }
        return null;
    }
    
    protected boolean getOneCheckBox(HttpServletRequest request, String parameter)
    {
        String paramValue = request.getParameter(parameter);
        if (paramValue != null)
        {
            if (paramValue.equalsIgnoreCase("true") || paramValue.equalsIgnoreCase("on")
                    || paramValue.equalsIgnoreCase("yes") || paramValue.equals("1"))
            {
                return true;
            }
        }
        return false;
    }
    
 

}
